define('views/item', ['text!/views/item.html', 'tool/cookie'], function(template, Cookie) {
  var ItemStatus = {
    'sold': 5, //售出
    'expired': 6, //过期
    'private': 10, //草稿
    'public': 20, //发布
    'active': 40, //活动中
  };
  return {
    template: template,
    replace: true,
    data: function() {
      return {
        statusStr: {
          5: '已售出',
          6: '已过期',
          10: '草稿',
          20: '出售中',
          40: '活动中'
        },
        userSelect: 0,
        smallPicList: false,
        item: {
          iid: 0,
          iName: '',
          cid: 0,
          uid: 0,
          des: '',
          price: '',
          browser: 0,
          place: '',
          status: 0,
          pic0: '',
          pic1: '',
          pic2: '',
          pic3: '',
          pic4: '',
          updateTime: 0,
          createTime: 0,
          reduction: 0,
          userName: '',
          avatar: '',
          telphone: '',
          qq: ''
        }
      };
    },
    props: ['user', 'box'],
    methods: {
      showPic: function() {
        this.box.name = 'showPic';
        this.box.data = this.showPicSrc;
      },
      getItem: function() {
        var vm = this;
        var data = {
          iid: vm.iid
        };
        if (Cookie.get('getByIid' + vm.iid) != 1) {
          data.first = true;
        }
        vm.$http.post('/item/getByIid', data).then(function(res) {
          res = res.data
          if (res.code !== 0) {
            console.log(res.message);
            return;
          }
          Cookie.set('getByIid' + vm.iid, 1, 3600);
          var item = vm.item;
          for (var i in item) {
            item[i] = res.data[i];
          }
        });
      },
      openQQ: function(qq) {
        if (qq === '') {
          alert('卖家太懒，没填写QQ号码');
          return;
        }
        location.href = 'tencent://message/?uin=' + qq + '&amp;Menu=yes&amp;Site=imconfig&amp;Service=300&amp;sigT=45a1e5847943b64c6ff3990f8a9e644d2b31356cb0b4ac6b24663a3c8dd0f8aa12a595b1714f9d45';
      }
    },
    computed: {
      showPicSrc: function() {
        var vm = this;
        return vm.item['pic' + vm.userSelect];
      },
      iid: function() {
        var iid = this.$route.query.iid;
        if (isNaN(iid)) {
          this.$router.replace({
            name: 'index'
          });
        }
        return this.$route.query.iid;
      },
      cName: function() {
        var categorys = this.$parent.categorys;
        for (var i = categorys.length - 1; i >= 0; i--) {
          if (categorys[i].cid == this.item.cid) {
            return categorys[i].cName;
          }
        }
      }
    },
    route: {
      data: function(){
        this.getItem();
      }
    }
  };
});